var style = Components.classes["@userstyles.org/style;1"].createInstance(Components.interfaces.stylishStyle);
const url = "http://example.com/foo/bar";
style.init(url, null, null, "Unit test - save original code no update", "/* original code */", false, null);
style.save();
assert("Style got original code for no reason", style.originalCode == null);
style.code = "/* new code */";
style.save();
assert("Style didn't get new code", style.code == "/* new code */");
assert("Style got original code though there is no possibility of update", style.originalCode == null);
} finally {
style.delete();
}
}
function testSaveOriginalCodeWithUpdate() {
try {
var style = Components.classes["@userstyles.org/style;1"].createInstance(Components.interfaces.stylishStyle);
const url = "http://example.com/foo/bar";
style.init(url, "http://example.com/update", "http://example.com/update", "Unit test - save original code with update", "/* original code */", false, null);
style.save();
assert("Style got original code for no reason", style.originalCode == null);
style.code = "/* new code */";
style.save();
assert("Style didn't get new code", style.code == "/* new code */");
assert("Style didn't get original code, it was: " + style.originalCode, style.originalCode == "/* original code */");
style = Style.find(style.id, 0);
style.code = "/* newer code */";
assert("Style's original code was updated", style.originalCode == "/* original code */");
} finally {
style.delete();
}
}
function testSaveOriginalCodeInitial() {
try {
var style = Components.classes["@userstyles.org/style;1"].createInstance(Components.interfaces.stylishStyle);
const url = "http://example.com/foo/bar";
style.init(url, "http://example.com/update", "http://example.com/update", "Unit test - save original code initial", "/* original code */", false, "/* original code */");
style.code = "/* new code */";
style.save();
assert("Style didn't get new code", style.code == "/* new code */");
assert("Style didn't get original code, it was: " + style.originalCode, style.originalCode == "/* original code */");
} finally {
style.delete();
}
}
function testLineBreak() {
try {
var style = Components.classes["@userstyles.org/style;1"].createInstance(Components.interfaces.stylishStyle);